package com.aqie.easy.stack;

import java.util.Stack;

/**
 *
 * 682. 棒球比赛
 * ["5","2","C","D","+"]
 */
public class CalPoints {
    public static int calPoints(String[] ops) {

        int ans = 0;
        // 记录当前轮的得分
        Stack<Integer> stack = new Stack<>();

        for (String op : ops){
            if (op.equals("C")){
                stack.pop();

            }else if(op.equals("+")){
                int top = stack.pop();
                int newtop = top + stack.peek();
                stack.push(top);
                stack.push(newtop);
            }else if(op.equals("D")){
                stack.push(2 * stack.peek());
            }else{
                stack.push(Integer.valueOf(op));
            }
        }
        for (Integer score: stack){
            ans += score;
        }
        return ans;
    }

    public static void main(String[] args) {
        int num = 5;
        String a = "1";
        Character b = '3';
        System.out.println(num - Integer.valueOf(a));
        System.out.println(num - b + '0');
        String[] ops = {"5","2","C","D","+"};
        calPoints(ops);
    }
}
